<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="组织机构" prop="orgId">
      <el-input v-model="dataForm.orgId" placeholder="组织机构"></el-input>
    </el-form-item>
    <el-form-item label="单位名称" prop="companyId">
      <el-input v-model="dataForm.companyId" placeholder="单位名称"></el-input>
    </el-form-item>
    <el-form-item label="序号" prop="serialNum">
      <el-input v-model="dataForm.serialNum" placeholder="序号"></el-input>
    </el-form-item>
    <el-form-item label="系统名称" prop="systemName">
      <el-input v-model="dataForm.systemName" placeholder="系统名称"></el-input>
    </el-form-item>
    <el-form-item label="网络类型" prop="networkType">
      <el-input v-model="dataForm.networkType" placeholder="网络类型"></el-input>
    </el-form-item>
    <el-form-item label="建设方式" prop="constructionMode">
      <el-input v-model="dataForm.constructionMode" placeholder="建设方式"></el-input>
    </el-form-item>
    <el-form-item label="浏览方式" prop="browsingMode">
      <el-input v-model="dataForm.browsingMode" placeholder="浏览方式"></el-input>
    </el-form-item>
    <el-form-item label="服务器部署" prop="serverDeployment">
      <el-input v-model="dataForm.serverDeployment" placeholder="服务器部署"></el-input>
    </el-form-item>
    <el-form-item label="服务器数量" prop="serverNum">
      <el-input v-model="dataForm.serverNum" placeholder="服务器数量"></el-input>
    </el-form-item>
    <el-form-item label="保密类型" prop="secrecyType">
      <el-input v-model="dataForm.secrecyType" placeholder="保密类型"></el-input>
    </el-form-item>
    <el-form-item label="等级保护级别" prop="secrecyGrade">
      <el-input v-model="dataForm.secrecyGrade" placeholder="等级保护级别"></el-input>
    </el-form-item>
    <el-form-item label="分级保护级别" prop="secrecyHierachical">
      <el-input v-model="dataForm.secrecyHierachical" placeholder="分级保护级别"></el-input>
    </el-form-item>
    <el-form-item label="测评时间" prop="evaluationTime">
      <el-input v-model="dataForm.evaluationTime" placeholder="测评时间"></el-input>
    </el-form-item>
    <el-form-item label="研发单位" prop="developmentCompany">
      <el-input v-model="dataForm.developmentCompany" placeholder="研发单位"></el-input>
    </el-form-item>
    <el-form-item label="用户数" prop="userNum">
      <el-input v-model="dataForm.userNum" placeholder="用户数"></el-input>
    </el-form-item>
    <el-form-item label="存储数" prop="storageNum">
      <el-input v-model="dataForm.storageNum" placeholder="存储数"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          orgId: '',
          companyId: '',
          serialNum: '',
          systemName: '',
          networkType: '',
          constructionMode: '',
          browsingMode: '',
          serverDeployment: '',
          serverNum: '',
          secrecyType: '',
          secrecyGrade: '',
          secrecyHierachical: '',
          evaluationTime: '',
          developmentCompany: '',
          userNum: '',
          storageNum: ''
        },
        dataRule: {
          orgId: [
            { required: true, message: '组织机构不能为空', trigger: 'blur' }
          ],
          companyId: [
            { required: true, message: '单位名称不能为空', trigger: 'blur' }
          ],
          serialNum: [
            { required: true, message: '序号不能为空', trigger: 'blur' }
          ],
          systemName: [
            { required: true, message: '系统名称不能为空', trigger: 'blur' }
          ],
          networkType: [
            { required: true, message: '网络类型不能为空', trigger: 'blur' }
          ],
          constructionMode: [
            { required: true, message: '建设方式不能为空', trigger: 'blur' }
          ],
          browsingMode: [
            { required: true, message: '浏览方式不能为空', trigger: 'blur' }
          ],
          serverDeployment: [
            { required: true, message: '服务器部署不能为空', trigger: 'blur' }
          ],
          serverNum: [
            { required: true, message: '服务器数量不能为空', trigger: 'blur' }
          ],
          secrecyType: [
            { required: true, message: '保密类型不能为空', trigger: 'blur' }
          ],
          secrecyGrade: [
            { required: true, message: '等级保护级别不能为空', trigger: 'blur' }
          ],
          secrecyHierachical: [
            { required: true, message: '分级保护级别不能为空', trigger: 'blur' }
          ],
          evaluationTime: [
            { required: true, message: '测评时间不能为空', trigger: 'blur' }
          ],
          developmentCompany: [
            { required: true, message: '研发单位不能为空', trigger: 'blur' }
          ],
          userNum: [
            { required: true, message: '用户数不能为空', trigger: 'blur' }
          ],
          storageNum: [
            { required: true, message: '存储数不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/auapplicationsystem/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orgId = data.auapplicationsystem.orgId
                this.dataForm.companyId = data.auapplicationsystem.companyId
                this.dataForm.serialNum = data.auapplicationsystem.serialNum
                this.dataForm.systemName = data.auapplicationsystem.systemName
                this.dataForm.networkType = data.auapplicationsystem.networkType
                this.dataForm.constructionMode = data.auapplicationsystem.constructionMode
                this.dataForm.browsingMode = data.auapplicationsystem.browsingMode
                this.dataForm.serverDeployment = data.auapplicationsystem.serverDeployment
                this.dataForm.serverNum = data.auapplicationsystem.serverNum
                this.dataForm.secrecyType = data.auapplicationsystem.secrecyType
                this.dataForm.secrecyGrade = data.auapplicationsystem.secrecyGrade
                this.dataForm.secrecyHierachical = data.auapplicationsystem.secrecyHierachical
                this.dataForm.evaluationTime = data.auapplicationsystem.evaluationTime
                this.dataForm.developmentCompany = data.auapplicationsystem.developmentCompany
                this.dataForm.userNum = data.auapplicationsystem.userNum
                this.dataForm.storageNum = data.auapplicationsystem.storageNum
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/auapplicationsystem/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'orgId': this.dataForm.orgId,
                'companyId': this.dataForm.companyId,
                'serialNum': this.dataForm.serialNum,
                'systemName': this.dataForm.systemName,
                'networkType': this.dataForm.networkType,
                'constructionMode': this.dataForm.constructionMode,
                'browsingMode': this.dataForm.browsingMode,
                'serverDeployment': this.dataForm.serverDeployment,
                'serverNum': this.dataForm.serverNum,
                'secrecyType': this.dataForm.secrecyType,
                'secrecyGrade': this.dataForm.secrecyGrade,
                'secrecyHierachical': this.dataForm.secrecyHierachical,
                'evaluationTime': this.dataForm.evaluationTime,
                'developmentCompany': this.dataForm.developmentCompany,
                'userNum': this.dataForm.userNum,
                'storageNum': this.dataForm.storageNum
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
